package com.demo2do.fms.admin.dao.data;

import java.math.BigDecimal;
import java.util.List;

import com.demo2do.core.persistence.annotation.Dao;
import com.demo2do.core.persistence.annotation.Query;
import com.demo2do.core.persistence.annotation.Variable;
import com.demo2do.fms.entity.data.business.FacilityDistance;

/**
 * 
 * @author Ysy
 *
 */
@Dao("hibernate")
public interface FacilityDistanceDao {

	/**
	 * load facility distance by organization, from_load_place and to_load_place.
	 * 
	 * mostly returns only one record
	 * 
	 * @param organizationId
	 * @param fromLoadPlaceId
	 * @param toLoadPlaceId
	 * @return
	 */
	@Query("FROM FacilityDistance WHERE organization.id = :organizationId AND fromLoadPlace.id = :fromLoadPlaceId AND toLoadPlace.id = :toLoadPlaceId AND disabled = false")
	public List<FacilityDistance> list(@Variable("organizationId") Long organizationId, @Variable("fromLoadPlaceId") Long fromLoadPlaceId, @Variable("toLoadPlaceId") Long toLoadPlaceId);
	
	/**
	 * load facility distance by organization, from_load_place and to_load_place
	 * 
	 * @param organizationId
	 * @param fromLoadPlaceId
	 * @param toLoadPlaceId
	 * @return
	 */
	@Query("SELECT facilityDistance FROM FacilityDistance WHERE organization.id = :organizationId AND fromLoadPlace.id = :fromLoadPlaceId AND toLoadPlace.id = :toLoadPlaceId")
	public BigDecimal load(@Variable("organizationId") Long organizationId, @Variable("fromLoadPlaceId") Long fromLoadPlaceId, @Variable("toLoadPlaceId") Long toLoadPlaceId);
}
